<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam - Shoutcast Module												/
/	Created by:		broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Support:		http://broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcasteb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0003																	/
/																							/
/========================================== JooSam ========================================*/
// Get url Params
$host = $_GET['host'];
$port = $_GET['port'];
$path = $_GET['path'];
$form = $_GET['form'];
$file = $_GET['file'];

// Strip Params
$host = strip_tags($host);
$port = strip_tags($port);
$path = strip_tags($path);
$form = strip_tags($form);
$file = strip_tags($file);

// Downloads
switch($form){

	// Format ASX	(Windows media player)
	case 'ASX':
		header('Content-Type: video/x-ms-asf; name="'.$file.'.asx"');
		header('Content-Transfer-Encoding: 7bit');
		header('Content-Disposition: attachment; filename="'.$file.'.asx"');
		echo "<ASX version = \"3.0\">\r\n<Entry>\r\n";
		if($path != ''){
			echo "<REF HREF=\"http://$host:$port/$path\" />\r\n";
		}
		else{
			echo "<REF HREF=\"http://$host:$port\" />\r\n";
		}
		echo "</Entry>\r\n</ASX>\r\n";
	break;

	// Format QTL	(iTunes)
	case 'QTL':
		header('Content-Type: application/x-quicktime-media-link; name="'.$file.'.qtl"');
		header('Content-Transfer-Encoding: 7bit');
		header('Content-Disposition: attachment; filename="'.$file.'.qtl"');
		echo "<?xml version=\"1.0\"?>\r\n";
		echo "<?quicktime type=\"application/x-quicktime-media-link\"?>\r\n";
		echo "<embed\r\n";
		echo "autoplay=\"true\"\r\n";
		echo "moviename=\"$file\"\r\n";
		if($path != ''){
			echo "src=\"icy://$host:$port/$path\"\r\n";
		}
		else{
			echo "src=\"icy://$host:$port\"\r\n";
		}
		echo "/>";
	break;

	// Format PLS (Winamp - Mobile)
	case 'PLS':
		header('Content-Type: audio/x-scpls; name="'.$file.'.pls"');
		header('Content-Transfer-Encoding: 7bit');
		header('Content-Disposition: attachment; filename="'.$file.'.pls"');
		echo "[playlist]\r\n";
		echo "NumberOfEntries=1\r\n";
		if($path != ''){
			echo "File1=http://$host:$port/$path\r\n";
		}
		else{
			echo "File1=http://$host:$port\r\n";
		}
		echo "Version=2";
	break;

	// Format RAM (RealPlayer)
	case 'RAM':
		header('Content-Type: audio/x-pn-realaudio; name="'.$file.'.ram"');
		header('Content-Transfer-Encoding: 7bit');
		header('Content-Disposition: attachment; filename="'.$file.'.ram"');
		if($path != ''){
			echo "http://$host:$port/$path\r\n";
		}
		else{
			echo "http://$host:$port/\r\n";
		}
	break;

	// Format M3U (Not used in mod_joosam_shoutcast)
	case 'M3U':
		header('Content-Type: audio/mpegurl; name="'.$file.'.m3u"');
		header('Content-Transfer-Encoding: 7bit');
		header('Content-Disposition: attachment; filename="'.$file.'.m3u"');
		echo "#EXTM3U\r\n";
		echo "#EXTINF:-1,$file\r\n";
		if($path != ''){
			echo "http://$host:$port/$path\r\n";
		}
		else{
			echo "http://$host:$port/\r\n";
		}
	break;

	// No Direct access
	default:
		echo 'No playlist selected';
	break;
}
?>